﻿using FinalPointSet.Model.Model;
using FinalPointSet.Model.Util;
using System;
using System.Diagnostics;
using System.Windows.Media.Animation;
using System.Windows;
using PG = System.Windows.Controls;

namespace FinalPointSet.View.Page.FieldMapping
{
    /// <summary>
    /// FieldMappingSettingPage.xaml 的交互逻辑
    /// </summary>
    public partial class FieldMappingSettingPage : PG.Page
    {
        public FieldMappingSettingPage()
        {
            InitializeComponent();
        }

        private void NavMenu_SelectionChanged(object sender, PG.SelectionChangedEventArgs e)
        {
            Debug.Print("NavMenu_SelectionChanged");

            if (NavMenu.SelectedItems[0] is not Menu menu)
            {
                Debug.Print("NavMenu_SelectionChanged选择为空");
                return;
            }

            if (PageFrame is null) return;
            PageUtil.Instance.Navigate(PageFrame, menu.Page);
        }
        private void PageFrame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            if (PageFrame.Content is PG.Page currentPage)
            {
                // 创建一个淡入动画
                DoubleAnimation fadeIn = new()
                {
                    From = 0,
                    To = 1,
                    Duration = new Duration(TimeSpan.FromSeconds(0.5)),
                    AutoReverse = false,
                    EasingFunction = new QuadraticEase
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                };

                // 将动画应用到Page的Opacity属性
                currentPage.BeginAnimation(OpacityProperty, fadeIn);
            }
        }

        private void PageFrame_ContentRendered(object sender, EventArgs e)
        {
            // 将新页面的初始Opacity设置为0，以便动画可以从0开始
            if (PageFrame.Content is PG.Page currentPage)
            {
                currentPage.Opacity = 0;
            }
        }
    }
}
